﻿using System;
using UnityEngine;

namespace SEXY
{
	// Token: 0x020002B2 RID: 690
	[Serializable]
	public class HsvColor
	{
		// Token: 0x06001168 RID: 4456 RVA: 0x00070ED8 File Offset: 0x0006F0D8
		public HsvColor(float hue, float saturation, float brightness)
		{
			if (hue < 0f || 360f < hue)
			{
				throw new ArgumentException("hueは0~360の値です。", "hue");
			}
			if (saturation < 0f || 1f < saturation)
			{
				throw new ArgumentException("saturationは0以上1以下の値です。", "saturation");
			}
			if (brightness < 0f || 1f < brightness)
			{
				throw new ArgumentException("brightnessは0以上1以下の値です。", "brightness");
			}
			this._h = hue;
			this._s = saturation;
			this._v = brightness;
		}

		// Token: 0x06001169 RID: 4457 RVA: 0x00070F74 File Offset: 0x0006F174
		public HsvColor(HsvColor src)
		{
			this._h = src._h;
			this._s = src._s;
			this._v = src._v;
		}

		// Token: 0x170001A8 RID: 424
		// (get) Token: 0x0600116A RID: 4458 RVA: 0x00070FA0 File Offset: 0x0006F1A0
		// (set) Token: 0x0600116B RID: 4459 RVA: 0x00070FA8 File Offset: 0x0006F1A8
		public float H
		{
			get
			{
				return this._h;
			}
			set
			{
				this._h = value;
			}
		}

		// Token: 0x170001A9 RID: 425
		// (get) Token: 0x0600116C RID: 4460 RVA: 0x00070FB4 File Offset: 0x0006F1B4
		// (set) Token: 0x0600116D RID: 4461 RVA: 0x00070FBC File Offset: 0x0006F1BC
		public float S
		{
			get
			{
				return this._s;
			}
			set
			{
				this._s = value;
			}
		}

		// Token: 0x170001AA RID: 426
		// (get) Token: 0x0600116E RID: 4462 RVA: 0x00070FC8 File Offset: 0x0006F1C8
		// (set) Token: 0x0600116F RID: 4463 RVA: 0x00070FD0 File Offset: 0x0006F1D0
		public float V
		{
			get
			{
				return this._v;
			}
			set
			{
				this._v = value;
			}
		}

		// Token: 0x06001170 RID: 4464 RVA: 0x00070FDC File Offset: 0x0006F1DC
		public void Copy(HsvColor src)
		{
			this._h = src._h;
			this._s = src._s;
			this._v = src._v;
		}

		// Token: 0x06001171 RID: 4465 RVA: 0x00071004 File Offset: 0x0006F204
		public static HsvColor FromRgb(Color rgb)
		{
			float r = rgb.r;
			float g = rgb.g;
			float b = rgb.b;
			float num = Math.Max(r, Math.Max(g, b));
			float num2 = Math.Min(r, Math.Min(g, b));
			float hue = 0f;
			if (num == num2)
			{
				hue = 0f;
			}
			else if (num == r)
			{
				hue = (60f * (g - b) / (num - num2) + 360f) % 360f;
			}
			else if (num == g)
			{
				hue = 60f * (b - r) / (num - num2) + 120f;
			}
			else if (num == b)
			{
				hue = 60f * (r - g) / (num - num2) + 240f;
			}
			float saturation;
			if (num == 0f)
			{
				saturation = 0f;
			}
			else
			{
				saturation = (num - num2) / num;
			}
			float brightness = num;
			return new HsvColor(hue, saturation, brightness);
		}

		// Token: 0x06001172 RID: 4466 RVA: 0x000710FC File Offset: 0x0006F2FC
		public static Color ToRgb(float h, float s, float v)
		{
			return HsvColor.ToRgb(new HsvColor(h, s, v));
		}

		// Token: 0x06001173 RID: 4467 RVA: 0x0007110C File Offset: 0x0006F30C
		public static Color ToRgb(HsvColor hsv)
		{
			float v = hsv.V;
			float s = hsv.S;
			float r;
			float g;
			float b;
			if (s == 0f)
			{
				r = v;
				g = v;
				b = v;
			}
			else
			{
				float num = hsv.H / 60f;
				int num2 = (int)Math.Floor((double)num) % 6;
				float num3 = num - (float)Math.Floor((double)num);
				float num4 = v * (1f - s);
				float num5 = v * (1f - s * num3);
				float num6 = v * (1f - s * (1f - num3));
				switch (num2)
				{
				case 0:
					r = v;
					g = num6;
					b = num4;
					break;
				case 1:
					r = num5;
					g = v;
					b = num4;
					break;
				case 2:
					r = num4;
					g = v;
					b = num6;
					break;
				case 3:
					r = num4;
					g = num5;
					b = v;
					break;
				case 4:
					r = num6;
					g = num4;
					b = v;
					break;
				case 5:
					r = v;
					g = num4;
					b = num5;
					break;
				default:
					throw new ArgumentException("色相の値が不正です。", "hsv");
				}
			}
			return new Color(r, g, b);
		}

		// Token: 0x06001174 RID: 4468 RVA: 0x00071228 File Offset: 0x0006F428
		public static Color ToRgba(HsvColor hsv, float alpha)
		{
			Color result = HsvColor.ToRgb(hsv);
			result.a = alpha;
			return result;
		}

		// Token: 0x04001346 RID: 4934
		private float _h;

		// Token: 0x04001347 RID: 4935
		private float _s;

		// Token: 0x04001348 RID: 4936
		private float _v;
	}
}
